﻿using System;
using System.Collections.Generic;
using Dapper;
using zhangmenren.Db;
using zhangmenren.Models;
namespace zhangmenren.Repository
{
    public class ItemRepository :BaseRepository
    {
        public int Add(ItemEntity entity)
        {
            string sql = @"INSERT INTO [Item] 
                            (ProductId
                            ,[Title]
                            ,Img
                            ,DataImg
                            ,Address,Detail
                            ,Lat,Lng,MiaoShu,AddDT)
                        VALUES
                            (@ProductId
                            ,@Title
                            ,@Img
                            ,@DataImg
                            ,@Address,@Detail
                            ,@Lat,@Lng,@MiaoShu,GETDATE())";
            return Execute(connection => connection.Execute(sql, entity));
        }

        public IEnumerable<ItemEntity> FindById(int id)
        {
            string sql = @"SELECT * FROM [Item] WHERE Id=@Id";
            return Execute(connection => connection.Query<ItemEntity>(sql, new { Id = id }));
        }
        public IEnumerable<ItemEntity> FindByProductId(int productId)
        {
            string sql = @"SELECT * FROM [Item] WHERE ProductId=@ProductId";
            return Execute(connection => connection.Query<ItemEntity>(sql, new { ProductId = productId }));
        }
    }
}
